package com.tuanzi.loan.business.service.statistics.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tuanzi.loan.business.repository.statistics.CreditCardKeeperStatRepository;
import com.tuanzi.loan.business.service.statistics.CreditCardKeeperStatService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.statistics.creditCardKeeper.CreditCardKeeperStatRequest;
import com.tuanzi.loan.vo.response.statistics.creditCardKeeper.CreditCardKeeperStatResponse;
import com.tuanzi.server.loan_base.model.bean.common.CommUserType;
import com.tuanzi.server.loan_base.model.db.CommProductChannel;

@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class CreditCardKeeperStatServiceImpl implements CreditCardKeeperStatService{
	
	@Autowired
	private CreditCardKeeperStatRepository creditCardKeeperStatRepository;
	
	public List<CommProductChannel> getChannelList() {
		return creditCardKeeperStatRepository.getChannelList();
	}
	
	public List<CommUserType> getUserTypeList() {
		return creditCardKeeperStatRepository.getUserTypeList();
	}
	
	
	public String getExcel(CreditCardKeeperStatRequest searchRequest) {
		Page<CreditCardKeeperStatResponse> allPageList = creditCardKeeperStatRepository.getAllList(searchRequest);
		
    	List<CreditCardKeeperStatResponse> list = allPageList.getContent();
    	StringBuffer sf = new StringBuffer();
		sf.append("时间,渠道,用户类型,日活,添卡人数,添卡数,网银导入数,邮箱导入数,手动添加数,更新账单数\r\n");
		if(list != null) {
			for(CreditCardKeeperStatResponse response : list) {
				sf.append(response.getTime()+",");
				sf.append(response.getChannel()+",");
				sf.append(response.getIs_new_user()+",");
				sf.append(response.getActivity_uv()+",");
				sf.append(response.getAdd_card_user_uv()+",");
				sf.append(response.getAdd_card_uv()+",");
				sf.append(response.getNet_bank_import_uv()+",");
				sf.append(response.getMail_import_uv()+",");
				sf.append(response.getManual_import_uv()+",");
				sf.append(response.getUpdate_bill_uv());
				sf.append("\r\n");
			}
		}
    	
    	return sf.toString();
    }
	
	public Page<CreditCardKeeperStatResponse> list(PageSearcher<CreditCardKeeperStatRequest> pageSearcher) {
		Page<CreditCardKeeperStatResponse> activityJoinListPage = creditCardKeeperStatRepository
				.getlistPage(pageSearcher.getSearchCondition(), pageSearcher.getPageable());
		return activityJoinListPage;
	}
	
	
}

























